home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / PHP / include / php / Zend / zend_operators.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-26  |  9.2 KB  |  239 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2001 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_OPERATORS_H
  22. #define ZEND_OPERATORS_H
  23.  
  24. #include <errno.h>
  25. #include <math.h>
  26.  
  27. #ifdef HAVE_IEEEFP_H
  28. #include <ieeefp.h>
  29. #endif
  30.  
  31.  
  32. #if 0&&WITH_BCMATH
  33. #include "ext/bcmath/libbcmath/src/bcmath.h"
  34. #endif
  35.  
  36. #define MAX_LENGTH_OF_LONG 18
  37. #define MAX_LENGTH_OF_DOUBLE 32
  38.  
  39. ZEND_API int add_function(zval *result, zval *op1, zval *op2);
  40. ZEND_API int sub_function(zval *result, zval *op1, zval *op2);
  41. ZEND_API int mul_function(zval *result, zval *op1, zval *op2);
  42. ZEND_API int div_function(zval *result, zval *op1, zval *op2);
  43. ZEND_API int mod_function(zval *result, zval *op1, zval *op2);
  44. ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2);
  45. ZEND_API int boolean_not_function(zval *result, zval *op1);
  46. ZEND_API int bitwise_not_function(zval *result, zval *op1);
  47. ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2);
  48. ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2);
  49. ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2);
  50. ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2);
  51. ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2);
  52. ZEND_API int concat_function(zval *result, zval *op1, zval *op2);
  53.  
  54. ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2);
  55. ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2);
  56. ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2);
  57. ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2);
  58. ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2);
  59. ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2);
  60. static inline int is_numeric_string(char *str, int length, long *lval, double *dval)
  61. {
  62.     long local_lval;
  63.     double local_dval;
  64.     char *end_ptr;
  65.  
  66.     if (!length) {
  67.         return 0;
  68.     }
  69.     
  70.     errno=0;
  71.     local_lval = strtol(str, &end_ptr, 10);
  72.     if (errno!=ERANGE && end_ptr == str+length) { /* integer string */
  73.         if (lval) {
  74.             *lval = local_lval;
  75.         }
  76.         return IS_LONG;
  77.     }
  78.  
  79.     errno=0;
  80.     local_dval = strtod(str, &end_ptr);
  81.     if (errno!=ERANGE && end_ptr == str+length) { /* floating point string */
  82.         if (! zend_finite(local_dval)) {
  83.             /* "inf","nan" and maybe other weird ones */
  84.             return 0;
  85.         }
  86.  
  87.         if (dval) {
  88.             *dval = local_dval;
  89.         }
  90. #if 0&&WITH_BCMATH
  91.         if (length>16) {
  92.             register char *ptr=str, *end=str+length;
  93.             
  94.             while(ptr<end) {
  95.                 switch(*ptr++) {
  96.                     case 'e':
  97.                     case 'E':
  98.                         /* scientific notation, not handled by the BC library */
  99.                         return IS_DOUBLE;
  100.                         break;
  101.                     default:
  102.                         break;
  103.                 }
  104.             }
  105.             return FLAG_IS_BC;
  106.         } else {
  107.             return IS_DOUBLE;
  108.         }
  109. #else
  110.         return IS_DOUBLE;
  111. #endif
  112.     }
  113.     
  114.     return 0;
  115. }
  116.  
  117. ZEND_API int increment_function(zval *op1);
  118. ZEND_API int decrement_function(zval *op2);
  119.  
  120. BEGIN_EXTERN_C()
  121. ZEND_API void convert_scalar_to_number(zval *op);
  122. ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
  123. ZEND_API void convert_to_long(zval *op);
  124. ZEND_API void convert_to_double(zval *op);
  125. ZEND_API void convert_to_long_base(zval *op, int base);
  126. ZEND_API void convert_to_null(zval *op);
  127. ZEND_API void convert_to_boolean(zval *op);
  128. ZEND_API void convert_to_array(zval *op);
  129. ZEND_API void convert_to_object(zval *op);
  130. ZEND_API void multi_convert_to_long_ex(int argc, ...);
  131. ZEND_API void multi_convert_to_double_ex(int argc, ...);
  132. ZEND_API void multi_convert_to_string_ex(int argc, ...);
  133. ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2);
  134. ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2);
  135. #define convert_to_string(op)            _convert_to_string((op) ZEND_FILE_LINE_CC)
  136.  
  137. ZEND_API double zend_string_to_double(const char *number, zend_uint length);
  138. END_EXTERN_C()
  139.  
  140. ZEND_API int zval_is_true(zval *op);
  141. ZEND_API int compare_function(zval *result, zval *op1, zval *op2);
  142. ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2);
  143. ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2);
  144.  
  145. ZEND_API void zend_str_tolower(char *str, unsigned int length);
  146. ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
  147. ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
  148. ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
  149. ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
  150. ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
  151. ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
  152. ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
  153. ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length);
  154.  
  155. ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
  156. ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2);
  157. ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2);
  158. ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2);
  159.  
  160. ZEND_API int zend_atoi(const char *str, int str_len);
  161.  
  162. #define convert_to_ex_master(ppzv, lower_type, upper_type)    \
  163.     if ((*ppzv)->type!=IS_##upper_type) {                    \
  164.         if (!(*ppzv)->is_ref) {                                \
  165.             SEPARATE_ZVAL(ppzv);                            \
  166.         }                                                    \
  167.         convert_to_##lower_type(*ppzv);                        \
  168.     }
  169.  
  170. #define convert_to_writable_ex_master(ppzv, lower_type, upper_type)    \
  171.     if ((*ppzv)->type!=IS_##upper_type) {                            \
  172.         SEPARATE_ZVAL(ppzv);                                        \
  173.         convert_to_##lower_type(*ppzv);                                \
  174.     }
  175.  
  176.  
  177. #define convert_to_boolean_ex(ppzv)    convert_to_ex_master(ppzv, boolean, BOOL)
  178. #define convert_to_long_ex(ppzv)    convert_to_ex_master(ppzv, long, LONG)
  179. #define convert_to_double_ex(ppzv)    convert_to_ex_master(ppzv, double, DOUBLE)
  180. #define convert_to_string_ex(ppzv)    convert_to_ex_master(ppzv, string, STRING)
  181. #define convert_to_array_ex(ppzv)    convert_to_ex_master(ppzv, array, ARRAY)
  182. #define convert_to_object_ex(ppzv)    convert_to_ex_master(ppzv, object, OBJECT)
  183. #define convert_to_null_ex(ppzv)    convert_to_ex_master(ppzv, null, NULL)
  184.  
  185. #define convert_to_writable_boolean_ex(ppzv)    convert_to_writable_ex_master(ppzv, boolean, BOOL)
  186. #define convert_to_writable_long_ex(ppzv)        convert_to_writable_ex_master(ppzv, long, LONG)
  187. #define convert_to_writable_double_ex(ppzv)        convert_to_writable_ex_master(ppzv, double, DOUBLE)
  188. #define convert_to_writable_string_ex(ppzv)        convert_to_writable_ex_master(ppzv, string, STRING)
  189. #define convert_to_writable_array_ex(ppzv)        convert_to_writable_ex_master(ppzv, array, ARRAY)
  190. #define convert_to_writable_object_ex(ppzv)        convert_to_writable_ex_master(ppzv, object, OBJECT)
  191. #define convert_to_writable_null_ex(ppzv)        convert_to_writable_ex_master(ppzv, null, NULL)
  192.  
  193.  
  194. #define convert_scalar_to_number_ex(ppzv)                            \
  195.     if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) {        \
  196.         if (!(*ppzv)->is_ref) {                                        \
  197.             SEPARATE_ZVAL(ppzv);                                    \
  198.         }                                                            \
  199.         convert_scalar_to_number(*ppzv);                            \
  200.     }
  201.  
  202.  
  203.  
  204. #define Z_LVAL(zval)        (zval).value.lval
  205. #define Z_BVAL(zval)        ((zend_bool)(zval).value.lval)
  206. #define Z_DVAL(zval)        (zval).value.dval
  207. #define Z_STRVAL(zval)        (zval).value.str.val
  208. #define Z_STRLEN(zval)        (zval).value.str.len
  209. #define Z_ARRVAL(zval)        (zval).value.ht
  210. #define Z_OBJPROP(zval)        (zval).value.obj.properties
  211. #define Z_OBJCE(zval)        (zval).value.obj.ce
  212. #define Z_RESVAL(zval)        (zval).value.lval
  213.  
  214. #define Z_LVAL_P(zval_p)        Z_LVAL(*zval_p)
  215. #define Z_BVAL_P(zval_p)        Z_BVAL(*zval_p)
  216. #define Z_DVAL_P(zval_p)        Z_DVAL(*zval_p)
  217. #define Z_STRVAL_P(zval_p)        Z_STRVAL(*zval_p)
  218. #define Z_STRLEN_P(zval_p)        Z_STRLEN(*zval_p)
  219. #define Z_ARRVAL_P(zval_p)        Z_ARRVAL(*zval_p)
  220. #define Z_OBJPROP_P(zval_p)        Z_OBJPROP(*zval_p)
  221. #define Z_OBJCE_P(zval_p)        Z_OBJCE(*zval_p)
  222. #define Z_RESVAL_P(zval_p)        Z_RESVAL(*zval_p)
  223.  
  224. #define Z_LVAL_PP(zval_pp)        Z_LVAL(**zval_pp)
  225. #define Z_BVAL_PP(zval_pp)        Z_BVAL(**zval_pp)
  226. #define Z_DVAL_PP(zval_pp)        Z_DVAL(**zval_pp)
  227. #define Z_STRVAL_PP(zval_pp)    Z_STRVAL(**zval_pp)
  228. #define Z_STRLEN_PP(zval_pp)    Z_STRLEN(**zval_pp)
  229. #define Z_ARRVAL_PP(zval_pp)    Z_ARRVAL(**zval_pp)
  230. #define Z_OBJPROP_PP(zval_pp)    Z_OBJPROP(**zval_pp)
  231. #define Z_OBJCE_PP(zval_pp)        Z_OBJCE(**zval_pp)
  232. #define Z_RESVAL_PP(zval_pp)    Z_RESVAL(**zval_pp)
  233.  
  234. #define Z_TYPE(zval)        (zval).type
  235. #define Z_TYPE_P(zval_p)    Z_TYPE(*zval_p)
  236. #define Z_TYPE_PP(zval_pp)    Z_TYPE(**zval_pp)
  237.  
  238. #endif
  239.